package com.example.crm.servlet;

import com.example.crm.service.IUserService;
import com.example.crm.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginchk")
public class LoginCheckServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取用户请求信息
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        //调用service查询
        IUserService service = new UserServiceImpl();
        boolean result = service.login(username,password);


        //打印结果跳转页面
        if (result){
            System.out.println("登陆成功");
            resp.sendRedirect("index.jsp");
        }else {
            System.out.println("登陆失败");
            resp.sendRedirect("login.jsp");
        }





    }
}
